// pages/cateSec/cateSec.js
import { getSecondCateList } from '../../miniprogram/utils/API/category'
import {elasticSearch} from '../../miniprogram/utils/API/search'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        idx: '',
        keyWord:'',
        placehold:'',
        title: "护肤",
        cateSecList: [],
        productList:[],
        swiperList:[
            {url:'/static/img/back2.png'},
            {url:'/static/img/header.png'},]
        },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let idx = options.id
        let title = options.title
        this.setData({
            idx,
            title,
            keyWord:title
        })
        wx.setNavigationBarTitle({
            title: title
        })
        this.getSecData()
        this.searchReq()
    },
    async getSecData() {
        let that = this
        let {idx} = this.data
        let res = await getSecondCateList()
        let buff = res.data[idx]
        console.log(buff,"buff");
        let  cateSecList =[]
         cateSecList= buff.map(item=>{
            item.name = item.name.split('/')[0]
            return item
        })

        that.setData({
            cateSecList
        })
    },


   async searchReq(){
       let data = {}
        data.catelogId = this.data.idx
        data.sort= "skuPrice_desc"
      let res = await elasticSearch(data)
      console.log("esResult:",res);
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})